#include "../tools.h"

class Solution {
public:
    vector<int> printListFromTailToHead(ListNode* head) {
        if (head == nullptr) return {};
        vector<int> res;

        ListNode* p = head;
        stack<ListNode*> st;
        while(p != nullptr){
            st.push(p);
            p = p->next;
        }

        while(!st.empty()){
            res.push_back(st.top()->val);
            st.pop();
        }

        return res;
    }
};


int main(int argc, char const *argv[])
{
    int arr[3] = {1, 2, 3};
    ListNode* head = create_list(arr, 3);
    show(head);

    Solution s;
    vector<int> res = s.printListFromTailToHead(head);

    show(head);
    show(res);



    return 0;
}
